/*   
 * Copyright (c) 2010-2020 DMGIS Ltd. All Rights Reserved.   
 *   
 * This software is the confidential and proprietary information of   
 * DMGIS. You shall not disclose such Confidential Information   
 * and shall use it only in accordance with the terms of the agreements   
 * you entered into with DMGIS.   
 *   
 */
package com.dmgis.qxfw.dataservice.yyweixin.controller;


import com.dmgis.qxfw.dataservice.bigdata.service.IInteractionService;
import com.dmgis.qxfw.dataservice.bigdata.service.ISpTourismService;
import com.dmgis.qxfw.dataservice.bigdata.service.IWeatherForecastService;
import com.dmgis.qxfw.dataservice.businessservice.api.domain.DbConfig;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.qx.heavy_forecast;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.zy.tour_actual_img;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.zy.tour_fcst;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.zy.travel_predict;
import com.dmgis.qxfw.dataservice.businessservice.common.domain.ForecastKey;
import com.dmgis.qxfw.dataservice.businessservice.common.domain.MyPoint;
import com.dmgis.qxfw.dataservice.businessservice.common.entity.TourTravelPath;
import com.dmgis.qxfw.dataservice.businessservice.common.util.DateTime;
import com.dmgis.qxfw.dataservice.businessservice.common.util.FileUtil;
import com.dmgis.qxfw.dataservice.businessservice.common.util.StringUtil;
import com.dmgis.qxfw.dataservice.businessservice.controller.ProcessRequestController;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.awt.geom.Point2D;
import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.util.*;
import java.util.Map.Entry;

/**
 * This class is used for 旅游微信后台服务接口
 * 
 * @author dsq
 * @version 1.0, 2018年10月30日 下午2:10:57
 */
@Controller
public class TourWxServiceController {

	@Resource
	private IWeatherForecastService weatherService;
	@Resource
	private IInteractionService interactionService;
	@Resource
	private ISpTourismService spTourService;

	private  final String operatingSystem;

	@Autowired
	public TourWxServiceController(String operatingSystem) {
		this.operatingSystem = operatingSystem;
	}


	ProcessRequestController pc = new ProcessRequestController();


	@RequestMapping(value = "weatherForecast", produces = "application/json;charset=utf-8")
	@ResponseBody
	public Object GetWeatherForecastData(HttpServletRequest request) {
		Object result = "[]";
		String method = request.getParameter("method");
		switch (method) {
		case "cityWeather":// 城市天气
		{
			String idOrName =request.getParameter("idOrName");// 站点标号
			String sc = request.getParameter("sc");// 时次
			String date = request.getParameter("date");// 日期,可用作测试
			String city =request.getParameter("city"); // 城市
			String localFlag = request.getParameter("localFlag");
			result = weatherService.getCityWeather(city, idOrName, sc, date, localFlag);
		}
			break;
		case "tourWeather":// 景区天气
		{
			String sc = request.getParameter("sc");// 时次
			String date = request.getParameter("date");// 日期,可用作测试
			String stationName = request.getParameter("stationName");
			result = weatherService.getTourWeather(stationName, sc, date,request);
		}
			break;
		case "loadStation": {
			result = weatherService.getAllStationCHN();
		}
			break;
		case "complete": // 定位成功操作
		{
			// String index = request.getParameter("index");
			String city = StringUtil.trimEnd(request.getParameter("stacity"), '市');
			String longitude = request.getParameter("longitude");
			String latitude = request.getParameter("latitude");
			result = weatherService.GetNearestStaIdByXY(longitude, latitude, city);
		}
			break;

		case "getTourStation": {
			// 获取所有的景点
			result = weatherService.getAllTourStaInfo();
		}
			break;
		case "getTourDetails": {
			String name = request.getParameter("name");
			String type = request.getParameter("type").trim();
			result = weatherService.getActImgStaInfo(name, type,request);
		}
			break;
		case "warning": {
			String warningId = request.getParameter("warningId").trim();
			result = weatherService.getWarningById(warningId);
		}
			break;
		default:
			break;
		}
		return result;
	}

	@RequestMapping(value = "getPicture", produces = "application/json;charset=utf-8")
	@ResponseBody
	public Object GetPicture(HttpServletRequest request) {
		Object result = "[]";
		String type = request.getParameter("type"); // 类型
		String element = request.getParameter("element");// 要素
		String date = request.getParameter("date");
		String path = request.getContextPath();
		String currentUrl = DbConfig.IP + path
				+ "/Temp/";
		String localPath ;
		if (operatingSystem.equals("Windows")){
			 localPath = request.getSession().getServletContext().getRealPath("/") + "Temp\\";// 临时文件目录
		}else {
			localPath = request.getSession().getServletContext().getRealPath("/") + "Temp/";
		}


		FileUtil.mkDirs(localPath);// 创建文件夹，生成多级目录
		FileUtil.ClearTempFiles(localPath, 1000);// 清除缓存
		switch (type) {
		case "区域站": {
			result = weatherService.getSKDZTList(element, currentUrl, localPath,date);
		}
			break;
		case "radarImg": {
			String ldType = request.getParameter("ldType");
			String yj = request.getParameter("yj");
			String station = request.getParameter("station");
			result = weatherService.getRadarList(ldType, yj, station, currentUrl, localPath, "other");
		}
			break;
		case "ytImg": {
			String ytType = request.getParameter("ytType");
			result = weatherService.getYTList(ytType, currentUrl, localPath);
		}
			break;
		case "gt_radarImg": {
			String ldType = request.getParameter("ldType");
			String yj = request.getParameter("yj");
			String station = request.getParameter("station");
			result = weatherService.getRadarList(ldType, yj, station, currentUrl, localPath, "gt");
		}
			break;
			case "gt_jdsenlImg": {
				String producttype = request.getParameter("producttype");
				result = weatherService.getFireList(producttype,request);
			}
			break;
			case "ProductImg": {
				String producttype = request.getParameter("producttype");
				result = weatherService.getProductImgList(producttype,request);
			}
			break;
		case "实景图片": {
			String stationname = request.getParameter("stationname");
			List<tour_actual_img> resulttour = weatherService.getSjtupian(currentUrl, localPath, stationname, request);
			if(resulttour!=null&&resulttour.size()>0){
				result = resulttour.get(0).getImagename();
		}
	}
			break;
		}
		return result;
	}

	@RequestMapping(value = "getYbPicture", produces = "application/json;charset=utf-8")
	@ResponseBody
	public Object getYbPicture(HttpServletRequest request) {
		Object result = "[]";
		String type = request.getParameter("type"); // 类型
		String element = request.getParameter("element");// 要素
		String date = request.getParameter("date");
		String path = request.getContextPath();
		String currentUrl = DbConfig.IP + path
				+ "/Temp/";
		String localPath ;
		if (operatingSystem.equals("Windows")){
			localPath = request.getSession().getServletContext().getRealPath("/") + "Temp\\";// 临时文件目录
		}else {
			localPath = request.getSession().getServletContext().getRealPath("/") + "Temp/";
		}


		FileUtil.mkDirs(localPath);// 创建文件夹，生成多级目录
		FileUtil.ClearTempFiles(localPath, 1000);// 清除缓存
		switch (type) {
			case "区域站": {
				result = weatherService.getYBDZTList(element, currentUrl, localPath,date);
			}
			break;
			case "radarImg": {
				String ldType = request.getParameter("ldType");
				String yj = request.getParameter("yj");
				String station = request.getParameter("station");
				result = weatherService.getRadarList(ldType, yj, station, currentUrl, localPath, "other");
			}
			break;
			case "ytImg": {
				String ytType = request.getParameter("ytType");
				result = weatherService.getYTList(ytType, currentUrl, localPath);
			}
			break;
			case "gt_radarImg": {
				String ldType = request.getParameter("ldType");
				String yj = request.getParameter("yj");
				String station = request.getParameter("station");
				result = weatherService.getRadarList(ldType, yj, station, currentUrl, localPath, "gt");
			}
			break;
			case "gt_jdsenlImg": {
				String producttype = request.getParameter("producttype");
				result = weatherService.getFireList(producttype,request);
			}
			break;
			case "ProductImg": {
				String producttype = request.getParameter("producttype");
				result = weatherService.getProductImgList(producttype,request);
			}
			break;
			case "实景图片": {
				String stationname = request.getParameter("stationname");
				List<tour_actual_img> resulttour = weatherService.getSjtupian(currentUrl, localPath, stationname, request);
				if(resulttour!=null&&resulttour.size()>0){
					result = resulttour.get(0).getImagename();
				}
			}
			break;
		}
		return result;
	}
	@RequestMapping(value = "interaction")
	@ResponseBody
	public Object Interaction(HttpServletRequest request) {
		Object result = "[]";
		String method = request.getParameter("methgetServiceDataod");

		String path = request.getContextPath();
		String currentUrl = DbConfig.IP + path
				+ "/Temp/";
		String localPath ;
		if (operatingSystem.equals("Windows")){
			localPath = request.getSession().getServletContext().getRealPath("/") + "Temp\\";// 临时文件目录
		}else {
			localPath = request.getSession().getServletContext().getRealPath("/") + "Temp/";
		}

		FileUtil.mkDirs(localPath);// 创建文件夹，生成多级目录
		FileUtil.ClearTempFiles(localPath, 1000);// 清除缓存
		if (!StringUtil.IsNullOrEmpty(method)) {
			switch (method) {
				case "locadStation": {
					result = interactionService.GetOrderPageInfo("",request);
				}
				break;
				case "saveOrderChange": {
					String orderCity = request.getParameter("orderCity");
					String orderWarning = request.getParameter("orderWarning");
					result = interactionService.SaveOrderChange("", orderCity, orderWarning);
				}
				break;
				case "text": {
					String city = request.getParameter("city");
					String flag = request.getParameter("flag");
					String fileName = request.getParameter("fileName");
					// String blobName = request.getParameter("blobName");
					String scaleWH = request.getParameter("scaleWH");
					// 判断是否有同名文件
					File file = new File(fileName);
					if (file.exists()) {
						if (interactionService.DelPicById(flag) == "1")
							result = "0|请不要重复提交，存在同名文件";
					} else {
						result = interactionService.UpDateTextInfo(city, flag, fileName, scaleWH);
					}
				}
				break;
				case "survey": {
					String text = request.getParameter("text");
					String type = request.getParameter("type");
					result = interactionService.UpDateStaSurvey(type, text);
				}
				break;
				case "showPic": {
					String imgPath = request.getParameter("imgUrl");
					result = imgPath;// 是否需要下载
				}
				break;
				case "picUrl": {
					result = interactionService.getPicture(currentUrl, localPath);
				}
				break;
				case "picUrlById": {
					String id = request.getParameter("id");
					result = interactionService.getPictureByID(currentUrl, localPath, id);
				}
				break;
			}
		} else {
			String flag = "0";
			CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(
					request.getSession().getServletContext());
			if (request instanceof MultipartHttpServletRequest) {
				// 将request变成多部分request
				MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
				Iterator<String> iter = multiRequest.getFileNames();
				// 检查form中是否有enctype="multipart/form-data"
				if (multipartResolver.isMultipart(request) && iter.hasNext()) {
					// 获取multiRequest 中所有的文件名
					while (iter.hasNext()) {
						// 一次遍历所有文件
						MultipartFile file = multiRequest.getFile(iter.next().toString());
						if (file != null) {
							String fileName = request.getParameter("fileName");
							String city = request.getParameter("city");
							String scaleWH = request.getParameter("scaleWH");
							// 判断是否有同名文件
							String imgPath = localPath + fileName;// 本地路径
							String urlPath = currentUrl + fileName;
							File localFile = new File(imgPath);
							if (localFile.exists()) {
								// if (interactionService.DelPicById(flag) ==
								// "1")
								flag = "0|请不要重复提交，存在同名文件";
							} else {
								try {
									file.transferTo(localFile);
								} catch (IllegalStateException e) {
									e.printStackTrace();
								} catch (IOException e) {
									e.printStackTrace();
								} // 保存到本地
								flag = interactionService.UploadPicPath(urlPath, imgPath);// 网络路径
								flag = interactionService.UpDateTextInfo(city, flag, fileName, scaleWH);
							}
						}
					}
				}
			}
			result = flag;
		}
		return result;
	}

	/**
	 * 获取特色旅游预测信息
	 * 
	 * @param request
	 * @return
	 * @author dsq
	 * @throws Exception
	 * @date 2018年11月2日
	 */
	@RequestMapping(value = "spTourism")
	@ResponseBody
	public Object GetSpTourism(HttpServletRequest request) throws Exception {
		Object result = "[]";
		String method = request.getParameter("method");
		String path = request.getContextPath();
		String currentUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path
				+ "/Temp/";
		String localPath ;
		if (operatingSystem.equals("Windows")){
			localPath = request.getSession().getServletContext().getRealPath("/") + "Temp\\";// 临时文件目录
		}else {
			localPath = request.getSession().getServletContext().getRealPath("/") + "Temp/";
		}

		FileUtil.mkDirs(localPath);// 创建文件夹，生成多级目录
		FileUtil.ClearTempFiles(localPath, 1000);// 清除缓存
		switch (method) {
		case "tourCourse": {
			result = "success";
		}
			break;
		default:
			break;
		case "spTourisum": {
			String date = request.getParameter("date");
			result = spTourService.getSpecialFcstInfo(date);
		}
			break;
		case "spPathFcst": {
				List<travel_predict> resultlist = new ArrayList<travel_predict>();
				result = "[";
				String[] types = new String[] { "花卉观赏气象", "采摘气象", "户外旅游气象", "自然景观气象", "热点景区气象" };
				for (int i = 0; i < types.length; i++) {
					resultlist = spTourService.getTourfcst(types[i]);
					if (resultlist != null && resultlist.size() > 0) {
						result += "{";
						result += "\"bigClass\":\"" + types[i] + "\",";
						String smallFcstInfo = "[";
						for (travel_predict travel : resultlist) {
							Integer fixtime = DateTime.now().GetMonth();
							String[] t = new String[2];
							if (travel.getTime().contains("-")) {
								t = travel.getTime().split("-");
							}
							if (fixtime > Integer.parseInt(t[0]) && fixtime < Integer.parseInt(t[1])) {
								ForecastKey selectKey = new ForecastKey();// 查询类
								String time = request.getParameter("date");//request.getParameter("date")
								String sc = "08";
								if (DateTime.now().GetHour() < 8 || DateTime.now().GetHour() >= 20) {
									sc = "20";
								}
								String sx = "24";
								int nTimes;
								nTimes = Integer.parseInt(sx);
								selectKey.setNTimes(nTimes);
								selectKey.setTimeChar(sc);
								selectKey.setDateChar(DateTime.parseDate(time).toDate());
								selectKey.setTourname(travel.getJqname());// 景区名称
								List<tour_fcst> fcstList = spTourService.getTourFcstInfo(selectKey);
								if (fcstList != null && fcstList.size() > 0) {
									Double maxtemp = 0.0;
									Double mintemp = 0.0;
									Double minrain = 0.0;
									Double maxrain = 0.0;
									Double minwind = 0.0;
									Double maxwind = 0.0;
									String weather = "";
									for (int tt = 0; tt < fcstList.size(); tt += 2) {
										if (fcstList.get(tt).getRain() > fcstList.get(tt + 1).getRain()) {
											minrain = fcstList.get(tt + 1).getRain();
											maxrain = fcstList.get(tt).getRain();
										} else {
											maxrain = fcstList.get(tt + 1).getRain();
											minrain = fcstList.get(tt).getRain();
										}
										if (fcstList.get(tt).getMintemp() > fcstList.get(tt + 1).getMintemp()) {
											mintemp = fcstList.get(tt + 1).getMintemp();
										} else {
											mintemp = fcstList.get(tt).getMintemp();
										}
										if (fcstList.get(tt).getMaxtemp() > fcstList.get(tt + 1).getMaxtemp()) {
											maxtemp = fcstList.get(tt).getMaxtemp();
										} else {
											maxtemp = fcstList.get(tt + 1).getMaxtemp();
										}
										if (Double.parseDouble(fcstList.get(tt).getWinds()) > Double
												.parseDouble(fcstList.get(tt + 1).getWinds())) {
											minwind = Double.parseDouble(fcstList.get(tt + 1).getWinds());
											maxwind = Double.parseDouble(fcstList.get(tt).getWinds());
										} else {
											minwind = Double.parseDouble(fcstList.get(tt).getWinds());
											maxwind = Double.parseDouble(fcstList.get(tt + 1).getWinds());
										}
										if (fcstList.get(tt).getWeather1().trim()
												.equals(fcstList.get(tt + 1).getWeather1().trim())) {
											weather = fcstList.get(tt).getWeather1().trim();
										} else {
											weather = fcstList.get(tt).getWeather1().trim() + "转"
													+ fcstList.get(tt + 1).getWeather1().trim();
										}
									}
									if (minrain >= travel.getRainmin() && maxrain <= travel.getRainmax()
											&& mintemp >= travel.getTempmin() && maxtemp <= 50.0
											&& minwind >= travel.getWindmin() && maxwind <= 10.0) {
										//minrain >= travel.getRainmin() && maxrain <= travel.getRainmax()
										//											&& mintemp >= travel.getTempmin() && maxtemp <= travel.getTempmax()
										//											&& minwind >= travel.getWindmin() && maxwind <= travel.getWindmax()
										smallFcstInfo += "{";
										smallFcstInfo += "\"smallClass\":\"" + travel.getSpotname() + "\",";
										smallFcstInfo += "\"suitableInfo\":\"" + "适宜（天气:" + weather + ";温度:" + maxtemp
												+ "℃;风速:" + maxwind + "）" + "\"";
										smallFcstInfo += "},";
									}
								}
							}
						}
						if (smallFcstInfo.endsWith(",")) {
							smallFcstInfo = smallFcstInfo.substring(0, smallFcstInfo.length() - 1);
						}
						smallFcstInfo = smallFcstInfo + "]";
						result += "\"smallFcstInfo\":" + smallFcstInfo + "";
						result += "},";
					}
				}
				if (((String) result).endsWith(",")) {
					result = ((String) result).substring(0, ((String) result).length() - 1);
				}
				result = result + "]";
			}
			break;
		case "gethotel": {
			result = spTourService.getHotel(currentUrl, localPath);
		}
			break;
		case "getHotelByID": {
			String id = request.getParameter("id");
			result = spTourService.getHotelByID(id, currentUrl, localPath);
		}
			break;
		case "gethotelDetails": {
			String id = request.getParameter("id");
			result = spTourService.getHotelInfo(id, currentUrl, localPath);
		}
			break;
		case "getDelicacy": {
			result = spTourService.getDelicacy(currentUrl, localPath);
		}
			break;
		case "getDelicacyByID": {
			String id = request.getParameter("id");
			result = spTourService.getDelicacyByID(id, currentUrl, localPath);
		}
			break;
		case "getDelicacyDetails": {
			String id = request.getParameter("id");
			result = spTourService.getDelicacyInfo(id, currentUrl, localPath);
		}
			break;
		case "bestTourPath": {
			String spotname = request.getParameter("spotname");
			String tourname = request.getParameter("tourname");
			String[] names = spotname.split(",");
			Double lon = 0.0;
			Double lat = 0.0;
			List<String> stationnames = new ArrayList<String>();
			Map<String, Double[]> map = new HashMap<String, Double[]>();
			Map<String, Double[]> resultD = new LinkedHashMap<String, Double[]>();
			List<TourTravelPath> paths = new ArrayList<TourTravelPath>();
			if (!spotname.equals("")) {
				for (int i = 0; i < names.length; i++) {
					if(!stationnames.contains(names[i])){
						stationnames.add(names[i]);
					}
				}
			}
			List<travel_predict> fcstList = spTourService.getTourSta1(stationnames);
			if (fcstList != null && fcstList.size() > 0) {
				for (travel_predict tour : fcstList) {
					Double[] lonlat = new Double[2];
					if (!tourname.contains(tour.getSpotname())) {
						lonlat[0] = tour.getLongitude();
						lonlat[1] = tour.getLatitude();
						map.put(tour.getSpotname(), lonlat);
					} else {
						lon = tour.getLongitude();
						lat = tour.getLongitude();
						lonlat[0] = lon;
						lonlat[1] = lat;
						resultD.put(tourname, lonlat);
					}
				}
			}
			for (int i = 0; i < fcstList.size(); i++) {
				String nextname = "";
				Point2D pointQD = new Point2D.Double(lon, lat);
				Double distance = Double.MAX_VALUE;
				for (Entry<String, Double[]> m : map.entrySet()) {
					Point2D pointZD = new Point2D.Double(m.getValue()[0], m.getValue()[1]);
					if (getDistance(pointQD, pointZD) < distance) {
						distance = getDistance(pointQD, pointZD);
						nextname = m.getKey();
						lon = m.getValue()[0];
						lat = m.getValue()[1];
					}
				}
				if (!map.isEmpty()) {
					Double[] lonlat = new Double[2];
					lonlat[0] = lon;
					lonlat[1] = lat;
					resultD.put(nextname, lonlat);
					// 移除已计算的项
					Set<?> mapset = map.entrySet();
					Iterator<?> iterator = mapset.iterator();
					while (iterator.hasNext()) {
						@SuppressWarnings("rawtypes")
						Entry mapEntry = (Entry) iterator.next();
						String key = mapEntry.getKey().toString();
						if (key.equals(nextname)) {
							iterator.remove();
						}
					}
				}
			}
			List<ArrayList<MyPoint>> list = new ArrayList<ArrayList<MyPoint>>();
			ArrayList<MyPoint> tempPos = new ArrayList<MyPoint>();
			for (Entry<String, Double[]> m : resultD.entrySet()) {
				MyPoint point = new MyPoint(m.getValue()[0], m.getValue()[1]);
				tempPos.add(point);
			}
			list.add(tempPos);
			for (Entry<String, Double[]> m : resultD.entrySet()) {
				TourTravelPath p = new TourTravelPath();
				p.setName(m.getKey());
				p.setLon(m.getValue()[0]);
				p.setLat(m.getValue()[1]);
				p.setPos(list);
				p.setPosArr(tempPos);
				paths.add(p);
			}
			result = paths;
		}
			break;
		}
		return result;
	}

	/**
	 * 通过AB点经纬度获取距离
	 * 
	 * @param pointA
	 *            A点(经，纬)
	 * @param pointB
	 *            B点(经，纬)
	 * @return 距离(单位：米)
	 */
	Double getDistance(Point2D pointA, Point2D pointB) {
		double EARTH_RADIUS = 6371393; // 平均半径,单位：m
		// 经纬度（角度）转弧度。弧度用作参数，以调用Math.cos和Math.sin
		double radiansAX = Math.toRadians(pointA.getX()); // A经弧度
		double radiansAY = Math.toRadians(pointA.getY()); // A纬弧度
		double radiansBX = Math.toRadians(pointB.getX()); // B经弧度
		double radiansBY = Math.toRadians(pointB.getY()); // B纬弧度
		double cos = Math.cos(radiansAY) * Math.cos(radiansBY) * Math.cos(radiansAX - radiansBX)
				+ Math.sin(radiansAY) * Math.sin(radiansBY);
		double acos = Math.acos(cos); // 反余弦值
		return EARTH_RADIUS * acos; // 最终结果
	}





    /**
     * 初始化重污染天气
     *
     * @param request
     * @param model
     * @return
     * @throws ParseException
     */
    @RequestMapping("/getheavyFcst")
    @ResponseBody
    public Object getheavyFcst(HttpServletRequest request, Model model) throws ParseException {
        Date dt = weatherService.getheavyFcst();
        DateTime date = new DateTime(dt);
        return date.toDateTimeString();
    }

    /**
     * 手动判断重污染天气
     *
     * @param request
     * @param model
     * @return
     * @throws ParseException
     */
    @RequestMapping("/getRGresult")
    @ResponseBody
    public Object getRGresult(HttpServletRequest request, Model model) throws Exception {
        String start_date = request.getParameter("start_date") + ":00:00";
        String type = request.getParameter("type");
        String result = "";
        List<heavy_forecast> resultList = weatherService.getRGresult(start_date, type);
        for (heavy_forecast heavy : resultList) {
            result = heavy.getPhenomenon();
        }
        return result;
    }

    /**
     * 自动判断重污染天气
     *
     * @param request
     * @param model
     * @return
     * @throws ParseException
     */
    @RequestMapping("/getZDresult")
    @ResponseBody
    public Object getZDresult(HttpServletRequest request, Model model) throws ParseException {
        String start_date = request.getParameter("start_date") + ":00:00";
        String type = request.getParameter("type");
        String result = "";
        List<heavy_forecast> resultList = weatherService.getRGresult(start_date, type);
        for (heavy_forecast heavy : resultList) {
            result = heavy.getPhenomenon();
        }
        return result;
    }
}
